DR='N:'
F1='DRUGS'
F2='DISPOS'
SELE 1
SET EXCLU OFF
USE &DR&F1 INDEX &DR&F1
SELE 2
SET EXCLU OFF
USE &DR&F2 INDEX &DR&F2
CLEA
MOIS=IIF(MONTH(DATE())=1,12,MONTH(DATE())-1)
ANNE=IIF(MONTH(DATE())=1,YEAR(DATE())-1,YEAR(DATE()))
DO CASE
   CASE MOIS=1
      JOUR=31
   CASE MOIS=2
      IF ANNE=1992
         JOUR=29
      ELSE
         JOUR=28
      ENDIF
   CASE MOIS=3
      JOUR=31
   CASE MOIS=4
      JOUR=30
   CASE MOIS=5
      JOUR=31
   CASE MOIS=6
      JOUR=30
   CASE MOIS=7
      JOUR=31
   CASE MOIS=8
      JOUR=31
   CASE MOIS=9
      JOUR=30
   CASE MOIS=10
      JOUR=31
   CASE MOIS=11
      JOUR=30
   CASE MOIS=12
      JOUR=31
ENDCASE
DO ADDRESSA
 @  8,  5  SAY "C. CONTROLLED INVENTORY REPORT"
 @ 11,  5  SAY "PRINT CONTROLLED INVENTORY REPORT"
 @ 10,  3  TO 12, 39
 @  7,  3  TO  9, 36    DOUBLE
KLR='N'
DO SET_DEV
IF KLR='Y'
   CLOSE DATA
   CLOSE INDEX
   RETURN
ENDIF
br=100
fl=0
hl=0
ttl=0
store 0 to ttl1,ttl2,ttl3,ttl4,ttl5
TOTVAL=0
VAL=0
DRUGVAL=0
DISPVAL=0
TOT=0
ctk=0
set devi to print
@ 0,0 say chr(18) pict 'x'
@ 0,0 say chr(27)+chr(77)
SELE 1
GO TOP
do while .not. eof()
   if br>58
      IF ctk>0
         BR=BR+1
         @ BR, 120 SAY "TO REPORT :"
         DO SAYG WITH BR,133,TOTVAL,'9,999,999.99','999,999,999'
*         @ BR, 133 SAY TOTVAL PICT "999,999,999"
         @ BR, 145 SAY "Rp."
      ENDIF
      if fl>0
         eject
      else
         fl=1
      endif
      cl=50
      hl=hl+1
      TITLE1=ALLTRIM(AEANAME)+' - '+ALLTRIM(AEACOUN)
      TITLE2=ALLTRIM(AEAADDR)
      @  0, 0 SAY TITLE1
      @  1, 0 SAY TITLE2
      @  2,0 SAY AEACITY
      @  2, 60 say '   INVENTORY REPORT    '
      @  3, 60 SAY '    CENTRAL  STORE     '
      @  4, 60 SAY '        DRUGS          '
      @  4,133 say 'DATE : '+DTOC(DATE())
      @  5,138 say 'PAGE : '
      @  5,145 say hl pict '999'
      @  6,120 say 'INVENTORY AS AT : '
      @  6,138 say  JOUR PICT "99"
      @  6,140 SAY "/"
      @  6,141 SAY MOIS PICT "99"
      @  6,143 SAY "/"
      @  6,144 SAY ANNE PICT "9999"
      @  7,  0 say repl('=',148)
      @  8,  0 say 'CODE'
      @  8, 13 say 'NAME'
      @  8, 30 say 'TYPE'
      @  8, 45 say 'CONTENT'
      @  8, 72 SAY "CENTRAL STORE PHYSICAL INVENTORY "
      @  8,120 SAY "UNIT PRICE"
      @  8,135 SAY "TOTAL VALUE"
      @  9, 56 SAY "BUYING UNIT"
      @  9, 75 SAY "+"
      @  9, 79 SAY "SELLING UNIT"
      @  9,95 SAY "PHYSICAL BALANCE"
      @ 10,0 say repl('-',148)
      ctk=1
      br=11
   endif
*   IF BR>=58
*      BR=BR+1
*      @ BR, 120 SAY "TO REPORT :"
*      @ BR, 133 SAY TOTVAL PICT "999,999,999"
*      @ BR, 145 SAY "Rp."
*      BR=100
*      LOOP
*   ENDIF
   br=br+1
   TOT=(ST_BOM_BUY*BUY_SELL_R)+ST_BOM_SEL
***   TOT=(ST_ACT_BUY*BUY_SELL_R)+ST_ACT_SEL
   VAL=TOT*SALE_PRICE
   DRUGVAL=DRUGVAL+VAL
   TOTVAL=TOTVAL+VAL
   @ BR,  0 SAY DRUG_CODE
   @ BR,  6 SAY DRUG_NAME
   @ BR, 27 SAY DRUG_TYPE
   @ BR, 40 SAY DRUG_QANT
   @ BR, 48 SAY DRUG_UNIT
   @ BR, 56 SAY ST_BOM_BUY PICT "9,999"
***   @ BR, 56 SAY ST_ACT_BUY PICT "9,999"
   @ BR, 62 SAY BUY_UNIT
   IF BUY_SELL_R<>1
      @ BR, 75 SAY "and"
      @ BR, 79 SAY ST_BOM_SEL PICT "9,999"
***      @ BR, 79 SAY ST_ACT_SEL PICT "9,999"
      @ BR, 86 SAY SELL_UNIT
   ENDIF
   @ BR, 100 SAY TOT PICT '999,999'
   @ BR, 108 SAY SELL_UNIT
   SPRIC=SALE_PRICE
   DO SAYG WITH BR,117,SPRIC,'999,999.99','99,999,999'
*   @ BR, 117 SAY SALE_PRICE PICT "99,999,999"
   @ BR, 128 SAY AEACURR+'.'
   DO SAYG WITH BR,134,VAL,'999,999.99','99,999,999'
*   @ BR, 134 SAY VAL PICT "99,999,999"
   @ BR, 145 SAY AEACURR+'.'
   BR=BR+1
   SKIP
ENDDO
BR=BR+1
@ BR, 120 SAY "TO REPORT :"
DO SAYG WITH BR,133,TOTVAL,'9,999,999.99','999,999,999'
*@ BR, 133 SAY TOTVAL PICT "999,999,999"
@ BR, 145 SAY "Rp."
BR=100
*HL=HL+1
FL=0
ctk=0
SELE 2
GO TOP
do while .not. eof()
   if br>58
      IF ctk>0
         BR=BR+1
         @ BR, 120 SAY "TO REPORT :"
         DO SAYG WITH BR,133,TOTVAL,'9,999,999.99','999,999,999'
*         @ BR, 133 SAY TOTVAL PICT "999,999,999"
         @ BR, 145 SAY "Rp."
      ENDIF
      if fl>0
         eject
      else
         fl=1
      endif
      cl=50
      hl=hl+1
      @  2, 60 say '   INVENTORY REPORT    '
      @  3, 60 SAY '    CENTRAL  STORE     '
      @  4, 60 SAY '     DISPOSABLE        '
      @  5,138 say 'PAGE : '
      @  5,145 say hl pict '999'
      @  6,105 say 'INVENTORY AS AT : '
      @  6,123 say  JOUR PICT "99"
      @  6,125 SAY "/"
      @  6,126 SAY MOIS PICT "99"
      @  6,128 SAY "/"
      @  6,129 SAY ANNE PICT "9999"
      @  7,  0 say repl('=',148)
      @  8,  0 say 'CODE'
      @  8, 13 say 'NAME'
      @  8, 30 say 'TYPE'
      @  8, 45 say 'CONTENT'
      @  8, 72 SAY "CENTRAL STORE PHYSICAL INVENTORY "
      @  8,120 SAY "UNIT PRICE"
      @  8,135 SAY "TOTAL VALUE"
      @  9, 56 SAY "BUYING UNIT"
      @  9, 75 SAY "+"
      @  9, 79 SAY "SELLING UNIT"
      @  9,100 SAY "TOTAL COUNT"
      @ 10,0 say repl('-',148)
      ctk=1
      br=11
   endif
*   IF BR>=58
*      BR=BR+1
*      @ BR, 120 SAY "TO REPORT :"
*      @ BR, 133 SAY TOTVAL PICT "999,999,999"
*      @ BR, 145 SAY "Rp."
*      BR=100
*      LOOP
*   ENDIF
   br=br+1
   TOT=(ST_BOM_BUY*BUY_SELL_R)+ST_BOM_SEL
***   TOT=(ST_ACT_BUY*BUY_SELL_R)+ST_ACT_SEL
   VAL=TOT*SALE_PRICE
   DISPVAL=DISPVAL+VAL
   TOTVAL=TOTVAL+VAL
   @ BR,  0 SAY DISP_CODE
   @ BR,  6 SAY DISP_NAME
   @ BR, 27 SAY DISP_TYPE
   @ BR, 40 SAY DISP_QANT
   @ BR, 48 SAY DISP_UNIT
   @ BR, 56 SAY ST_BOM_BUY PICT "9,999"
***   @ BR, 56 SAY ST_ACT_BUY PICT "9,999"
   @ BR, 62 SAY BUY_UNIT
   IF BUY_SELL_R<>1
      @ BR, 75 SAY "and"
      @ BR, 79 SAY ST_BOM_SEL PICT "9,999"
***      @ BR, 79 SAY ST_ACT_SEL PICT "9,999"
      @ BR, 86 SAY SELL_UNIT
   ENDIF
   @ BR, 100 SAY TOT PICT '999,999'
   @ BR, 108 SAY SELL_UNIT
   SPRIC=SALE_PRICE
   DO SAYG WITH BR,117,SPRIC,'999,999.99','99,999,999'
*   @ BR, 117 SAY SALE_PRICE PICT "99,999,999"
   @ BR, 128 SAY "Rp.  ="
   DO SAYG WITH BR,134,VAL,'999,999.99','99,999,999'
*   @ BR, 134 SAY VAL PICT "99,999,999"
   @ BR, 145 SAY "Rp."
   BR=BR+1
   SKIP
ENDDO
BR=BR+1
@ BR, 120 SAY "TO REPORT :"
DO SAYG WITH BR,133,TOTVAL,'9,999,999.99','999,999,999'
*@ BR, 133 SAY TOTVAL PICT "999,999,999"
@ BR, 145 SAY "Rp."
BR=100
FL=0
if br>60
   if fl>0
      eject
   else
      fl=1
   endif
   cl=50
   hl=hl+1
   @  2, 60 say '   INVENTORY REPORT    '
   @  3, 60 SAY '    CENTRAL  STORE     '
   @  4, 60 SAY '  DRUGS & DISPOSIBLE   '
   @  5,138 say 'PAGE : '
   @  5,145 say hl pict '999'
   @  6,105 say 'INVENTORY AS AT : '
   @  6,123 say  JOUR PICT "99"
   @  6,125 SAY "/"
   @  6,126 SAY MOIS PICT "99"
   @  6,128 SAY "/"
   @  6,129 SAY ANNE PICT "9999"
   @  7,  0 say repl('=',148)
   @  10,20 SAY "GRAND TOTAL (DRUGS)      :"
   DO SAYG WITH 10,56,DRUGVAL,'9,999,999.99','999,999,999'
*   @  10,56 SAY DRUGVAL PICT "999,999,999"
   @  12,20 SAY "GRAND TOTAL (DISPOSABLE) :"
   DO SAYG WITH 12,56,DISPVAL,'9,999,999.99','999,999,999'
*   @  12,56 SAY DISPVAL PICT "999,999,999"
   @  15,20 SAY "GRAND TOTAL (CUMULATIVE) :"
   DO SAYG WITH 15,56,TOTVAL,'9,999,999.99','999,999,999'
*   @  15,56 SAY TOTVAL PICT  "999,999,999"
ENDIF
@ 0,0 SAY CHR(18) PICT 'X'
SET DEVI TO SCREEN
CLOSE DATA
CLOSE INDEX
RETURN